package com.better.common.jwtauth.secruity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;

@Data
public class JWTUserDetails implements UserDetails {
    private final String id;
    private final String userName;
    private final String password;
    private final String email;
    private final Collection<? extends GrantedAuthority> authorities;
    private final Date lastPasswordResetDate;
    private String name;    // 姓名
    private String phone;    // 电话
    private String mobile;    // 手机
    private String userType;// 用户类型	1:学校账户，2：班级账户
    private String statue;     //状态（试用，正式｛已付费｝，停用）
    private String remark;    //备注
    private Integer schoolType; //学校类型（小学0，初中1，中小学2，高中3）
    private String schoolId;//学校ID
    private String schoolName;//学校名称
    private String classId; //班级ID
    private String className;//班级名称
    private String gradeId; //年级ID
    private String gradeName;//年级名称
    private String studyId; //学期id
    private String studyName; //学期name
    private final boolean accountNonExpired;
    private final boolean accountNonLocked;
    private final boolean credentialsNonExpired;
    private final boolean enabled;

    public JWTUserDetails(
            String id,
            String username,//登录名称
            String password,//登录密码
            String email,
            String name,//用户名
            String phone,
            String mobile,
            Integer schoolType,//学校类型
            String schoolId,//学校ID
            String schoolName,//学校名称
            String classId, //班级ID
            String className,//班级名称
            String gradeId, //年级ID
            String gradeName,//年级名称
            Collection<? extends GrantedAuthority> authorities,
            Date lastPasswordResetDate,
            String studyId,
            String studyName,
            String userType) {
        this.id = id;
        this.userName = username;
        this.password = password;
        this.email = email;
        this.authorities = authorities;
        this.lastPasswordResetDate = lastPasswordResetDate;
        this.name = name;
        this.phone = phone;
        this.mobile = mobile;
        this.schoolType = schoolType;
        this.schoolId = schoolId;
        this.schoolName = schoolName;
        this.classId = classId;
        this.className = className;
        this.gradeId = gradeId;
        this.gradeName = gradeName;
        this.accountNonExpired = true;
        this.accountNonLocked = true;
        this.credentialsNonExpired = true;
        this.enabled = true;
        this.studyId = studyId;
        this.studyName = studyName;
        this.userType=userType;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    public String getEmail() {
        return email;
    }

    @JsonIgnore
    public String getId() {
        return id;
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return enabled;
    }

    @JsonIgnore
    public Date getLastPasswordResetDate() {
        return lastPasswordResetDate;
    }
}
